/* Declarations for parsefasta.

   Copyright (C) Liu Tao

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License
   as published by the Free Software Foundation; either version 2 of
   the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#ifndef __FASTAIO_H_
#define __FASTAIO_H_

/* Store Fasta sequence, including id, sequence, length, and type*/
typedef struct _Fasta
{
  char* id;
  char* seq;
  long  length;
  char  stype;			/* stype: R, RNA; D, DNA; P, protein */
} Fasta;

/* for store fasta struct in a 1-direction chain */
typedef struct _FastaRecord
{
  Fasta *fasta;
  struct _FastaRecord *next;
} FastaRecord;

/* parse a fasta file */
FastaRecord* parse_file (FILE * fp);

/* parse fasta records from text block 
   all stuff are in memory.
 */
FastaRecord* parse_text ( const char* text);
/* parse a single fasta record */
FastaRecord* parse_record ( const char* text);

/* free fasta recordS */
void free_records ( FastaRecord* target_record);

/* create a fasta record */
FastaRecord* new_record (const char* id, const char* seq);

/* duplicate a fasta record */
FastaRecord* dup_record (const FastaRecord * src_record);

/* uppercase letters in fasta sequence */
int up_record (const FastaRecord * record);

/* lowercase letters in fasta sequence */
int low_record (const FastaRecord * record);

/* get a subrecord [start,end), and `start' is from 0*/
FastaRecord* sub_record (const FastaRecord * record, int start, int end);

/* mask a part of record 
   if record type is 0(nucleotide), mask with 'N' or 1(protein) with 'X'.
*/
int mask_record (const FastaRecord *record, int start, int end);

/* write a record */
int write_record (FILE *fp, FastaRecord* fr);

/* write records */
int write_records (FILE *fp, FastaRecord* fr);

/* splice a record by a given letter */
FastaRecord* splice_c_record (const FastaRecord* src_record, const char letter);

/* splice a record by a given string */
FastaRecord* splice_s_record (const FastaRecord* src_record);

/* replace char X with char Y */
int replace_record (const FastaRecord *record, char X, char Y);

/* guess type of a sequence from the first 100 bp */
char guess_type ( const FastaRecord * record );

/* reverse complement a fasta sequence */
char * revcomp (char *comp, char *seq );

#endif
